1. Field of the Invention
The present invention relates generally to byte code instrumentation (BCI) in a data processing system, and in particular to a computer implemented method, data processing system, and computer program product for automatic discovery of the Java classloader delegation hierarchy.
2. Description of the Related Art
Java is an object-oriented programming language and environment focusing on defining data as objects and the methods that may be applied to those objects. Java is designed to solve a number of problems in modern programming practice. Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating system architectures. To enable a Java application to execute on different types of data processing systems, a compiler typically generates an architecture-neutral file format, so that the compiled code is executable on many processors, given the presence of the Java runtime system. The Java compiler generates byte code instructions that are non-specific to any particular computer architecture. A byte code is a machine independent code generated by the Java compiler and executed by a Java interpreter. A Java interpreter is a module that alternately decodes and executes a byte code. The decoding of the byte code places the instruction into an executable form for the computer on which the code is to be executed. Then, the instruction is executed by the computer. These byte code instructions are designed to be easy to interpret on any machine and easily translated on the fly into native machine code.
The Java Virtual Machine (JVM) is a virtual computer component. A virtual computer component is an abstract computer component that only resides in memory. A JVM includes components necessary to run a program on a computer, including an interpreter. The JVM allows Java programs to be executed on different platforms as opposed to only a single platform. Typically, computer programs are originally written in a human-readable format called source code, which is then compiled (by a computer program called a “compiler”) into a format that can be directly implemented by a computer system. Conventionally, programs must be compiled for one specific platform (i.e., processing unit and operating system combination) such that a program that has been compiled for one platform will often not run on a different platform. Java programs are compiled for the JVM rather than for any particular platform (although there are typically different versions of the JVM adapted to different platforms). In this manner, Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating system architectures.
There are a number of approaches to dynamically loading interdependent components of executable code (such as plug-ins, bundles, etc.) in modern programming languages. Dynamically loading means to load one or more components of an application after the application has begun execution. In the Java programming language, classes are dynamically loaded using a classloader as an application program executes.
The classloader is responsible for searching for a particular class, and making that class available to the run-time system if found. In object-oriented programming, a class consists of a collection of types of encapsulated instance variables and types of methods, possibly with implementation of those types, together with a constructor function that can be used to create objects of the class. Java class loading is based on a delegation model, wherein a classloader first delegates the class loading responsibility to its immediate parent classloader.
Byte Code Instrumentation (BCI) is a widely adopted technique used to alter Java virtual machine byte code instructions. Byte code instrumentation typically introduces additional Java classes into the byte code instructions to profile Java applications. For load-time and dynamic byte code instrumentation, deployment of the newly added classes in the byte code instructions is a time consuming and non-trivial process. However, this deployment is the key to successful loading/execution of the altered byte code. Although some application vendors provide dedicated locations for inserting BCI code, there is currently no mechanism in the existing art which enables the added Java classes (BCI code) to be deployed automatically.
With the existing manual methods for BCI code deployment, there are several drawbacks. One drawback is that the Java class deployment is a static process. Whenever there is a change in the product being instrumented, there is a possibility that the BCI code will not work in the new environment. BCI code deployment locations are also limited to the configurations supported by a product. In some circumstances, even if a deployment location is identified, deployment to that location is not possible. In addition, discovering the correct classloader to use to load the new classes can be a protracted process. Without a standard and systematic method for discovering the correct classloader to use, programmers can only rely on product documentation, product implementation details (if available), and experimenting with multiple possibilities by actually loading the BCI code.